<?php
require('io/FileOp.php');


$xml=simplexml_load_file('a.html');


ExtForm();
AndroidForm();



function AndroidMisc($i){
	writeFile('android:id="@+id/widget'.$i.'"');
	writeFile('android:layout_width="wrap_content"');
	writeFile('android:layout_height="wrap_content"');
}

function AndroidForm(){
	global $xml;
	$before_form = $xml->body;
	
	OpenFile('a.xml');

	foreach($before_form->form as $form){
	$ii = 0;
		foreach($form->input as $input){
			$ii++;
			switch($input['type']){
				case 'checkbox':
					writeFile("<CheckBox");
					AndroidMisc($ii);
					writeFile('android:text=""');
					writeFile('>');
					writeFile('</CheckBox>');
				break;
				case 'radio':
					writeFile("<RadioButton");
					AndroidMisc($ii);
					writeFile('android:text=""');
					writeFile('>');
					writeFile('</RadioButton>');
				break;			
				case 'submit':
					writeFile("<Button");
					AndroidMisc($ii);
					writeFile('android:text="'.$input['value'].'"');
					writeFile('>');
					writeFile('</Button>');
				break;
			}
		}
	}
	CloseFile();
}
function ExtForm(){
	global $xml;
	$before_form = $xml->body;

	OpenFile('a.js');
	
	
	foreach($before_form->form as $form){
		$b = "var ".$form['name']." = new Ext.FormPanel({";
		writeFile($b);
		writeFile("	labelWidth: 75,");
		writeFile("	frame: true,");
		$b = "	url: '";
		$b.= $form['action'];
		$b.="',";
		writeFile($b);
		writeFile("	items: [{");
		
		foreach($form->input as $input){
		
			switch($input['type']){
				case 'text':
				case 'password';
					$b = "		fieldLabel: '',";
					writeFile(b);
					$b = "		name: '";
					$b.=$input['name'];
					$b.="',";
					writeFile($b);
					$b = "		value: '".$input['value']."',";
					writeFile($b);
					$b = "		xtype: '";
					$b.=$input['type'];
					$b.="'";
					writeFile($b);
				break;
				case 'checkbox':
				break;
				case 'radio':
				break;			
				case 'submit':
				break;
			}
			
		}
	}
	CloseFile();
}


?>